using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GameShow.Forms
{
    public partial class frmSlideShow00 : frmBase
    {
        private StreamReader sr = null;
        private bool IsSecondAccess = false;
        private List<Label> packageList = new List<Label>();
        public frmSlideShow00(int parent)
        {
            InitializeComponent();
            AppInstance.CloseForm(parent);
        }

        protected override void watcher_Changed(object sender, System.IO.FileSystemEventArgs e)
        {
            if (!IsSecondAccess && e.Name.Equals("control.txt") && e.ChangeType == WatcherChangeTypes.Changed)
            {
                IsSecondAccess = true;
                if (e.Name.Equals("control.txt"))
                {
                    ProcessControl();
                }
                else if (e.Name.Equals("Result01.txt"))
                {
                    ProcessResult(1);
                }
                else if (e.Name.Equals("Result02.txt"))
                {
                    ProcessResult(2);
                }
                else if (e.Name.Equals("Result03.txt"))
                {
                    ProcessResult(3);
                }
                else if (e.Name.Equals("Result04.txt"))
                {
                    ProcessResult(4);
                }
                else if (e.Name.Equals("Result05.txt"))
                {
                    ProcessResult(5);
                }
            }
        }

        private void ProcessResult(int clientId)
        {

        }

        private void ProcessControl()
        {
            string line = string.Empty;
            sr = new StreamReader(slideDataPath + "control.txt");

            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
            }
            sr.Close();

            string[] cmdArr = line.Split(new char[] { ' ' });
            if (cmdArr.Length > 0)
            {
                if (cmdArr[0].Equals(Common.SlideControl.DisplayQuestion.ToString()))
                {
                    DisplayQuestion(int.Parse(cmdArr[1]));
                }
                else if (cmdArr[0].Equals(Common.SlideControl.DisplayResult.ToString()))
                {
                    DisplayResult(int.Parse(cmdArr[1]));
                }
                else if (cmdArr[0].Equals(Common.SlideControl.Wait.ToString()))
                {
                    DisplayWaitScreen();
                }
            }
        }

        protected override void DisplayQuestion(int questionId)
        {
            base.DisplayQuestion(questionId);
        }

        protected override void DisplayResult(int questionId)
        {
            base.DisplayResult(questionId);
        }

        protected override void DisplayWaitScreen()
        {
            base.DisplayWaitScreen();
        }
    }
}